# -*- coding: utf-8 -*-
# @Time    : 2018/4/18 14:05
# @Author  : Soft
# @File    : RecordExcel.py
# @Software: PyCharm
# #Desc    : 记录导出导入
from module.ExeclUtils import *

def getRecordExecl(records):
    """
    获取记录的execl
    :param records: 记录数据
    """
    status = [u'缺勤', u'出勤', u'迟到', u'请假']
    style  = [red, white, blue, yellow]
    book  = getWriteBook()
    sheet = book.add_sheet("RECORD")
    title = ['序号', '课程名', '学生名', '考勤状态', '位置偏差', '签到时间']
    for i, v in enumerate(title):
        sheet.write(0, i, v.decode('utf-8'))
    for row, re in zip(range(1, len(records) + 1), records):
        k = re.get('rd_status')
        sheet.write(row, 0, row)
        sheet.write(row, 1, re.get('k').get('k_name'))
        sheet.write(row, 2, re.get('stu').get('stu_name'))
        sheet.write(row, 3, status[k], style[k])
        sheet.write(row, 4, str(re.get('deviation')) + " M")
        sheet.write(row, 5, re.get('rd_time'))
    xls_file = saveTempFile(book, "record.xls")
    return xls_file
